package com.servlet;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import com.domain.User;
import com.service.userService;

/**
 * 
 * 功能描述： 注册Servlet
 * 
 * Version： 1.0
 * 
 * date： 2016年6月22日 上午11:32:43
 * 
 * @author：XiaoBingBy
 *
 */
public class registerServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public registerServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		User myUser = new User();//JavaBean 
		
		//把数据封装到Bean中
		try {
			BeanUtils.populate(myUser, request.getParameterMap());
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		userService userService = new userService(); //user表业务方法
		
		boolean b = userService.register(myUser);
		
		if (b) {
			response.sendRedirect(request.getContextPath()+"/login.jsp");
		} else {
			System.out.println("注册失败执行方法");
		}
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
